<?php
	session_start();
	require_once('functions.php');
	
	$username = $_POST['username'];
	$password = $_POST['password'];
	
	$login_attempt = login($username, $password);
	
	if($login_attempt)
	{	
		$_SESSION['account_type_code'] = $login_attempt['account_type_code'];
		$_SESSION['name'] = $login_attempt['sname'];
		$_SESSION['username'] = $login_attempt['username'];
		$_SESSION['sid'] = $login_attempt['sid'];
		
		if($login_attempt['account_type_code'] == 1)
		{		
			header("Location:admin.php");
			exit;
		}
		if($login_attempt['account_type_code'] == 2)
		{
			header("Location:user.php");
			exit;
		}
	}
	else
	{
		header("Location:index.php?response_msg=Login Failed!");
		exit;
	}
?>